import httpUtils from "./XmlHttpTool";
var rankiItem = cc.Class({
    name: 'rankiItem',
    properties: {
       
        rankleaveimage:cc.String,
        rankName:cc.String,
        rankheadimage:cc.Integer,
        score:cc.String
      
    }
});

cc.Class({
    extends: cc.Component,

    properties: {
        items: {
            default: [],
            type: rankiItem
        },//代码几个item格子 初始化
        itemPrefab: cc.Prefab,//预制节点 代表cell内容详情
        myheadSprite:cc.Node,
        mynameLabel:cc.Label,
        myscoreLabel:cc.Label,
        mysignSprite:cc.Node,
        ListAllScrollView:cc.Node,
        RankingAllView:cc.Node,
        myrankLabel:cc.Label,
        rankCloseBtn:cc.Button,
        friendScrolView:cc.Node
       
    },

    onLoad () {
     

    },

    init(){

        if(this.items.length>0){
            this.node.removeAllChildren();
        }

        console.log("排行榜")
        var that=this
        httpUtils.NhttpPost("/marmot/honorlist",{},function(res){
     
            console.log("好友请求成功",res)
            that.myscoreLabel.getComponent(cc.Label).string=res["user_info"]["score"]
            that.mynameLabel.getComponent(cc.Label).string=res["user_info"]["name"]

            if(res["user_info"]["user_rank"]==1){

                let _this = that
                cc.loader.loadRes("leave_1", cc.SpriteFrame, function (err, spriteFrame) {
             
                  _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
     
                });

            }else if(res["user_info"]["user_rank"]==2){

                let _this = that
                cc.loader.loadRes("leave_2", cc.SpriteFrame, function (err, spriteFrame) {
             
                  _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
     
                });

            }else if(res["user_info"]["user_rank"]==3){

                let _this = that
                cc.loader.loadRes("leave_3", cc.SpriteFrame, function (err, spriteFrame) {
             
                  _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
     
                });

            }else if(res["user_info"]["user_rank"]=="未上榜"){

               let _this = that
                cc.loader.loadRes("未上榜", cc.SpriteFrame, function (err, spriteFrame) {
             
                  _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
     
                });

            }
            else{
                
                  let _this = that
                  that.myrankLabel.node.active=true
                    that.myrankLabel.getComponent(cc.Label).string=res["user_info"]["user_rank"]
                cc.loader.loadRes("排名底框", cc.SpriteFrame, function (err, spriteFrame) {
             
                  _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
     
                });  
            
            }
            var _this=that
            cc.loader.load({url: res["user_info"]["avatar"], type: 'png'}, function(err,img){

                var mylogo  = new cc.SpriteFrame(img); 
    
                _this.myheadSprite.getComponent(cc.Sprite).spriteFrame = mylogo;
    
                _this.myheadSprite.width=82
    
                _this.myheadSprite.height=82
                
            });
            
          that.items=res["list"]
            for (var i = 0; i < that.items.length; ++i) {
    
                var item = cc.instantiate(that.itemPrefab);
                that.node.addChild(item);
                item.getComponent('listPrefab').init(that.items[i]);
             
            }

        
        },function(failres){

            console.log("好友请求错误",failres)
        })


    },
    
    start () {

    },

    closeClick:function(){


        var changebig = cc.scaleTo(0.02,1.2);

        var finish = cc.callFunc(function(){
    
            var that=this
          var changesmail = cc.scaleTo(0.08,1.0);

          var smaillfinish=cc.callFunc(function(){

            that.ListAllScrollView.active=false

          })

          var seq2 = cc.sequence(changesmail,smaillfinish)
          this.rankCloseBtn.node.runAction(seq2)
       

       }, this);
    
       var seq = cc.sequence(changebig,finish)

       this.rankCloseBtn.node.runAction(seq)
        
    },

    worldListClick:function(){

    },

    friendListClick:function(){
     
        this.ListAllScrollView.active=false
        this.RankingAllView.active=true
        this.friendScrolView.getComponent("facebookScrollView").init()
    
    }

    // update (dt) {},
});
